﻿$(document).ready(function () {
	$("input[id $= btDeploy]").click(function () {

		// Disable Inputs
		$inputs = $("Form").find("input, select, button, textarea");
		$inputs.attr("disabled", "disabled");


		// Collect Form Data
		var SQLServerName = $("input[id $= txtSQLServerName]").val();
		var SQLAdminUserName = $("input[id $= txtSQLAdminUserName]").val();
		var SQLAdminPassword = $("input[id $= txtSQLAdminPassword]").val();
		var DBName = $("input[id $= txtAppDataBaseName]").val();
		var AppUserName = $("input[id $= txtAppUserName]").val();
		var AppUserPassword = $("input[id $= txtAppUserPassword]").val();

		var DeployApplicationParams = {
			i_ServerName: SQLServerName,
			i_SQLAdminUserName: SQLAdminUserName,
			i_SQLAdminPassword: SQLAdminPassword,
			i_DBName: DBName,
			i_AppUserName: AppUserName,
			i_AppUserPassword: AppUserPassword
			
		}

		//Make a WebMethod call (Defined in Commons.js)
		CallWebMethod({
			WebMethodAdress: "ApplicationDeployer.aspx/DeployApplication",
			Data: DeployApplicationParams,
			
			SuccessCallbackFunction: function (response, textStatus, jqXHR) {
				alert(response.d);
			},

			
			ErrorCallbackFunction:function (jqXHR, textStatus, errorThrown) {
				alert(textStatus, errorThrown);
			},
			
			CompleteCallbackFunction: function () {
				$inputs.removeAttr("disabled");
			}
		});

	return false;
	});

});